//
//  BaseViewController.m
//  jinneng
//
//  Created by mac on 2020/7/29.
//  Copyright © 2020年 jznrj. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    if (@available(iOS 13.0, *)) {
//        UIView *statusBar = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame];
//        statusBar.backgroundColor = [ColorUtil titleColor];
//       [[UIApplication sharedApplication].keyWindow addSubview:statusBar];
//    } else {
//         UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
//         if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]){
//                 //设置状态栏背景色
//                statusBar.backgroundColor = [ColorUtil titleColor];
//        }
//    }
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
    UINavigationBar * bar = self.navigationController.navigationBar;
    CGRect barFrame = self.navigationController.navigationBar.frame;
     UIImage *bgImage = [ColorUtil navigationBarColor:[ColorUtil titleColor] BarSize:barFrame alphe:1.0];
     [bar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
     [bar setTintColor:[UIColor whiteColor]];
     [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateNormal];
     [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    
    //ios 15系统
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appperance = [[UINavigationBarAppearance alloc]init];
        //添加背景色
        appperance.backgroundColor = [ColorUtil titleColor];
        appperance.shadowImage = [[UIImage alloc]init];
        appperance.shadowColor = nil;
        [appperance setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
        self.navigationController.navigationBar.standardAppearance = appperance;
        self.navigationController.navigationBar.scrollEdgeAppearance = appperance;
        
 
    }
    
    CGRect statusFrame = [[UIApplication sharedApplication] statusBarFrame];
    self.titleHeight = SCREENSIZE.width*0.22+ statusFrame.size.height;

    self.edgesForExtendedLayout = UIRectEdgeNone;
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    configuration.userContentController = [WKUserContentController new];
       
    WKPreferences *preferences = [WKPreferences new];
    preferences.javaScriptCanOpenWindowsAutomatically = YES;
    configuration.preferences = preferences;
    self.view.backgroundColor = [UIColor whiteColor];
       
    [self.view addSubview:self.jznWebView];
      
    self.webViewBridge = [WKWebViewJavascriptBridge bridgeForWebView:self.jznWebView];
    [self.webViewBridge setWebViewDelegate:self];
    
    [self.view addSubview:self.loadingProgressView];
    [self.loadingProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
    }];
    
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    self.loginDto = [LoginDto mj_objectWithKeyValues: [userDefault objectForKey: @"userInfo"]];
    
}

-(void) viewWillAppear:(BOOL)animated{
//    [self.view addSubview:self.loadingProgressView];
//    [self.loadingProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.view);
//    }];
    

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

   
-(JznWebView*) jznWebView{
    if (!_jznWebView) {
        _jznWebView = [[JznWebView alloc]init];
        _jznWebView.scrollView.bounces = YES ;
        _jznWebView.opaque = NO;
        _jznWebView.backgroundColor = [UIColor whiteColor];
    }
    return _jznWebView;
}

-(ActivityIndicatorView*) loadingProgressView{
    
    if (!_loadingProgressView) {
        
        _loadingProgressView = [[ActivityIndicatorView alloc]init];
    }
    return _loadingProgressView;
}


@end
